package cn.mn.ac.rocketmq.props;

import com.aliyun.openservices.ons.api.PropertyKeyConst;
import com.aliyun.openservices.ons.api.PropertyValueConst;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.Objects;
import java.util.Properties;

/**
 * @author: zhuCan
 * @date: 2019/10/30 16:38
 * @description: rocket 基础配置属性
 */
@ConfigurationProperties(prefix = "rocket")
public class RocketProperties {

    private static final int DEFAULT_CONSUMER_THREAD_NUMS = 20;
    private static final int DEFAULT_CONSUMER_NUMS = 2;

    private String secretKey = "secretKey";

    private String address = "http://localhost:80";

    private String accessKey = "accessKey";

    private boolean enable = true;

    private String group;

    private Integer consumerThreadNums = DEFAULT_CONSUMER_THREAD_NUMS;

    private Integer consumerNums = DEFAULT_CONSUMER_NUMS;

    private Long delay = 5000L;

    public Properties rocketProperties() {
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.AccessKey, accessKey);
        properties.put(PropertyKeyConst.SecretKey, secretKey);
        properties.put(PropertyKeyConst.NAMESRV_ADDR, address);
        return properties;
    }

    public String getSecretKey() {
        return secretKey;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getAccessKey() {
        return accessKey;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }

    public boolean getEnable() {
        return enable;
    }

    public void setEnable(boolean enable) {
        this.enable = enable;
    }

    public Long getDelay() {
        return delay;
    }

    public void setDelay(Long delay) {
        this.delay = delay;
    }

    public boolean isEnable() {
        return enable;
    }

    public Integer getConsumerThreadNums() {
        return consumerThreadNums;
    }

    public void setConsumerThreadNums(Integer consumerThreadNums) {
        this.consumerThreadNums = Objects.isNull(consumerThreadNums) || consumerThreadNums < 0 ? DEFAULT_CONSUMER_THREAD_NUMS : consumerThreadNums;
    }

    public Integer getConsumerNums() {
        return consumerNums;
    }

    public void setConsumerNums(Integer consumerNums) {
        this.consumerNums = Objects.isNull(consumerNums) || consumerNums < 0 ? DEFAULT_CONSUMER_NUMS : consumerNums;
    }

    public String getGroup() {
        return group;
    }

    public void setGroup(String group) {
        this.group = group;
    }
}
